#pragma once

#include "pch.h"
#include <wrl.h>
#include <wrl/implements.h>
#include <windows.storage.streams.h>

class NativeBuffer :
	public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::WinRtClassicComMix>,
	ABI::Windows::Storage::Streams::IBuffer,
	Windows::Storage::Streams::IBufferByteAccess>
{
public:
	static Windows::Storage::Streams::IBuffer^ CreateNativeBuffer(BYTE *buffer, UINT32 length)
	{
		NativeBuffer *instance = nullptr;
		Microsoft::WRL::Details::MakeAndInitialize<NativeBuffer>(&instance, buffer, length);
		return reinterpret_cast<Windows::Storage::Streams::IBuffer^>(instance);
	}
	
	virtual ~NativeBuffer();

	STDMETHODIMP RuntimeClassInitialize(BYTE *buffer, UINT32 length);

	STDMETHODIMP Buffer(BYTE **value);

	STDMETHODIMP get_Capacity(UINT32 *value);

	STDMETHODIMP get_Length(UINT32 *value);

	STDMETHODIMP put_Length(UINT32 value);

private:
	BYTE *m_buffer;
	UINT32 m_length;
};